//
//  HuYuSealed.m
//  HuYu
//
//  Created by Macbook on 6/12/16.
//  Copyright © 2016年 huyu. All rights reserved.
//

#import "HuYuSealed.h"
#import <UIKit/UIKit.h>
@implementation HuYuSealed
//创建textField,无图片，无密码。
+(UITextField *)createTextFieldFrame:(CGRect )frame backgroundColor:(UIColor*)color placeholder:(NSString *)str pColor:(UIColor*)pcolor clearsOnBeginEditing:(BOOL)clearsOnBeginEditing font:(CGFloat)font clearButtonMode:(UITextFieldViewMode)mode textClolr:(UIColor*)tColor{
    
    UITextField *textField = [[UITextField alloc]init];
    textField.frame = frame ;
    textField.backgroundColor = color;
    //textField.borderStyle = UITextBorderStyleLine;
    textField.placeholder = str;
    
    textField.attributedPlaceholder =  [[NSAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:pcolor}];
    //再次编辑就清空
    textField.clearsOnBeginEditing =clearsOnBeginEditing;
    textField.font = [UIFont systemFontOfSize:font];
    textField.clearButtonMode = mode;
    textField.textColor = tColor;
    return textField;
}
+(UITextField *)CReateTextFieldFrame:(CGRect )frame placeholder:(NSString *)str pColor:(UIColor*)pcolor font:(CGFloat)font clearButtonMode:(UITextFieldViewMode)mode
{
    UITextField *textField = [[UITextField alloc]init];
    textField.frame = frame ;
    textField.placeholder = str;
    textField.attributedPlaceholder =  [[NSAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:pcolor}];
    textField.font = [UIFont systemFontOfSize:font];
    textField.clearButtonMode = mode;
    return textField;
}
//创建textField,无图片，有密码。
+(UITextField *)createPasTextFieldFrame:(CGRect )frame backgroundColor:(UIColor*)color secureTextEntry:(BOOL)secureTextEntry placeholder:(NSString *)str pColor:(UIColor*)pcolor clearsOnBeginEditing:(BOOL)clearsOnBeginEditing font:(CGFloat)font{
    
    UITextField *textField = [[UITextField alloc]init];
    textField.frame = frame ;
    textField.backgroundColor = color;
    textField.secureTextEntry =secureTextEntry;
    textField.attributedPlaceholder =  [[NSAttributedString alloc] initWithString:str attributes:@{NSForegroundColorAttributeName:pcolor}];
    textField.font = [UIFont systemFontOfSize:font];
    //再次编辑就清空
    textField.clearsOnBeginEditing =clearsOnBeginEditing;
    return textField;
}

+ (UILabel *)creatLabelWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor*)textColor textAlignment:(NSTextAlignment)textAlignment font:(CGFloat)font backGroundColor:(UIColor*)Bcolor{
    
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    
    label.text = text;
    
    label.textAlignment = textAlignment;
    
    label.textColor = textColor;
    
    label.font = [UIFont systemFontOfSize:font];
    
    label.backgroundColor = Bcolor;
    return label;
}
+ (UILabel *)CreatLabelWithFrame:(CGRect)frame text:(NSString *)text textColor:(UIColor*)textColor font:(CGFloat)font
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];

    label.text = text;
    
    label.textColor = textColor;
    
    label.font = [UIFont systemFontOfSize:font];
        
    return label;
}

+ (UIButton *)creatButtonWithFrame:(CGRect)frame target:(id)target sel:(SEL)sel tag:(NSInteger)tag image:(NSString *)name title:(NSString *)title titleColor:(UIColor *)color backGroundColor:(UIColor*)Color font:(CGFloat)font layer:(BOOL)Mlayer cornerRadius:(CGFloat)Radius
{
    
    UIButton *button = nil;
    if (name)
    {
        //创建图片按钮
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        //设置背景图片
        [button setBackgroundImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
        button.backgroundColor = Color;
        button.layer.masksToBounds = YES;
        button.layer.cornerRadius =Radius;
        if (title)
        {
            //创建 图片 和 标题按钮
            [button setTitle:title forState:UIControlStateNormal];
            [button setTitleColor:color forState:UIControlStateNormal];
            button.backgroundColor = Color;
            button.layer.masksToBounds = YES;
            button.layer.cornerRadius =Radius;
        }
    }
    else if(title)
    {
        //创建标题按钮
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:title forState:UIControlStateNormal];
        
        [button setTitleColor:color forState:UIControlStateNormal];
    }
    button.titleLabel.font = [UIFont systemFontOfSize:20];
    button.backgroundColor = Color;
    button.frame = frame;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    button.tag = tag;
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius =Radius;
    
    [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    return button;
}
+(UIButton *)CreateBtnFrame:(CGRect)frame title:(NSString *)title titleColor:(UIColor *)color target:(id)target action:(SEL)action

{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    btn.frame = frame;
    
    [btn setTitle:title forState:UIControlStateNormal];
    
    [btn setTitleColor:color forState:UIControlStateNormal];
        
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
    
}
+(UIButton *)CReateBtnFrame:(CGRect)frame bgImageName:(NSString *)bgImageName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    [btn setBackgroundImage:[UIImage imageNamed:bgImageName] forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return btn;
}

+ (UIButton *)CREeatButtonWithFrame:(CGRect)frame target:(id)target sel:(SEL)sel title:(NSString *)title titleColor:(UIColor *)color backGroundColor:(UIColor*)Color font:(CGFloat)font layer:(BOOL)Mlayer cornerRadius:(CGFloat)Radius
{
    
   UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:title forState:UIControlStateNormal];
    
    [button setTitleColor:color forState:UIControlStateNormal];

    button.titleLabel.font = [UIFont systemFontOfSize:20];
    button.backgroundColor = Color;
    button.frame = frame;
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius =Radius;
    
    [button addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
return button;
}
//实现方法imageview
+(UIImageView *)creatImageViewFrame:(CGRect)frame image:(UIImage *)image{
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:frame];
    [imageView setImage:image];
    return  imageView;
    
}
+(UIImageView *)creatImageViewFrame:(CGRect)frame imageName:(NSString *)imageName layer:(BOOL)Mlayer cornerRadius:(CGFloat)Radius{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:frame];
    UIImage *image = [UIImage imageNamed:imageName];
    [imageView setImage:image];
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius =Radius;
    return imageView;
    
}

//创建view
+(UIView *)createViewFrame:(CGRect)frame backgroundColor:(UIColor *)color layer:(BOOL)Mlayer cornerRadius:(CGFloat)Radius{
    
    UIView *view = [[UIView alloc]initWithFrame:frame];
    view.backgroundColor = color;
    view.layer.masksToBounds = YES;
    view.layer.cornerRadius =Radius;
    return view;
}
+ (UIView*)createViewFrame:(CGRect)frame backgroundColor:(UIColor*)color{
    
    UIView *view = [[UIView alloc]initWithFrame:frame];
    view.backgroundColor = color;
    return view;
}
+ (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {
    
    NSString *labelText = label.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:space];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
    label.attributedText = attributedString;
    [label sizeToFit];
    
}
+ (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = font;
    [label sizeToFit];
    return label.frame.size.width;
}
@end
